package com.zzg.base.response;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.zzg.enums.ResponseStatusEnum;

import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = false)
public class BaseResponse<T> implements Serializable {
	/**
	* 
	*/
	private static final long serialVersionUID = 1L;
	private Integer status;
	private String message;
	private T data;

	public BaseResponse(Integer status, String message, T data) {
		this.status = status;
		this.message = message;
		this.data = data;
	}

	public BaseResponse(ResponseStatusEnum status, T data) {
		this(status.getCode(), status.getMessage(), data);
	}

	public String toJson() {
		T t = this.getData();
		if (t instanceof List || t instanceof Collection) {
			return JSONObject.toJSONString(this, SerializerFeature.WriteNullListAsEmpty);
		} else {
			return JSONObject.toJSONString(this, SerializerFeature.WriteMapNullValue);
		}
	}
}
